using System;

namespace SlSyncLibrary
{
    public class ExecutorOperation
    {
        // Fields
        private object[] _args;
        private Delegate _operation;
        private Action _action;

        // Methods
        internal ExecutorOperation(Delegate operation, object[] args)
        {
            this._operation=operation;
            this._args=args;
        }

        internal ExecutorOperation(Action action)
        {
            this._action=action;
            this._args=null;
        }

        internal void Invoke()
        {
            if (_operation!=null)
                this._operation.DynamicInvoke(this._args);
            else
                this._action.DynamicInvoke(_args);
        }

        internal string Name
        {
            get
            {
                if (_action!=null)
                    return _action.Method.Name;
                else if (_operation!=null)
                    return _operation.Method.Name;
                else
                    return "(Unknown)";

            }
        }
        internal bool IsEndBlock
        {
            get
            {
                if (_action!=null&&_action.Method.DeclaringType==typeof(Executor)&&
                    _action.Method.Name=="NotifyEndBlock")
                    return true;
                else
                    return false;
            }
        }
    }
}